/*
 * @name: 抽奖商品管理
 * @Author: along
 * @Date: 2020-06-09
 */
<template>
    <div class="container zdLuckDraw">
        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <el-radio-group
                        v-model="head.luck_status"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-radio-button :label=" '' ">
                            全部
                        </el-radio-button>
                        <el-radio-button :label="0">
                            待开奖
                        </el-radio-button>
                        <el-radio-button :label="1">
                            已开奖
                        </el-radio-button>
                    </el-radio-group>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">商品名称:</p>
                    <el-input
                        v-model="head.shop_name"
                        placeholder="请输入内容"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">可抽奖人群:</p>
                    <el-select
                        v-model="head.shop_leavel"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in leavelData"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">上架状态:</p>
                    <el-select
                        v-model="head.show_status"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in showList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">活动形式:</p>
                    <el-select
                        v-model="head.lottery_scope"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in activeList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">开奖时间:</p>
                    <el-date-picker
                        v-model="head.luck_start_time"
                        type="datetime"
                        placeholder="请选择开始日期"
                        align="right"
                        size="small"
                        :picker-options="fnGetPickerOptions()"
                        @change="getTableData(1)"
                        :style="{width: '182px'}"
                    />
                    <span :style="{padding: '0 10px'}">
                        -
                    </span>
                    <el-date-picker
                        v-model="head.luck_end_time"
                        type="datetime"
                        placeholder="请选择结束日期"
                        align="right"
                        size="small"
                        :picker-options="fnGetPickerOptions()"
                        @change="getTableData(1)"
                        :style="{width: '182px'}"
                    />
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="fnLuckCheck()"
                    >
                        中奖查询核销
                    </el-button>
                    <el-button
                        type="primary"
                        size="small"
                        @click="()=>{
                            this.$router.push({
                                name: 'zdLuckLeavel'
                            })
                        }"
                    >
                        管理显示等级
                    </el-button>
                    <el-button
                        type="primary"
                        size="small"
                        @click="fnSubsidyDialog()"
                    >
                        补贴抽奖流水
                    </el-button>
                    <el-button
                        type="primary"
                        size="small"
                        @click="()=>{
                            this.$refs.searchDialog.showDialog()
                        }"
                    >
                        批量添加商品
                    </el-button>
                    <el-button
                        type="primary"
                        size="small"
                        @click="()=>{
                            this.$router.push({
                                name: 'zdLuckCreate',
                                query: {
                                    type: 'add'
                                }
                            })
                        }"
                    >
                        添加抽奖商品
                    </el-button>
                </div>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            ref="zdLuckDraw"
            @sort-change="handleSortChanged"
            @select="fnSelect"
            @select-all="fnSelectAllTop"
            @selection-change="handleSelectionChange"
        >
            <el-table-column
                type="selection"
                width="40"
                fixed="left"
            />
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="center"
            />
            <el-table-column
                prop="lottery_title"
                label="商品名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="150"
            />
            <el-table-column
                prop="goods_title"
                label="所链自营商品"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="110"
            >
                <template slot-scope="scope">
                    <p
                        class="cursor-font"
                        @click="fnJumpShop(scope.row)"
                    >
                        {{ scope.row.goods_title }}
                    </p>
                </template>
            </el-table-column>
            <el-table-column
                prop="lottery_price"
                label="开奖价格"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                sortable
                :width="100"
            />
            <el-table-column
                prop="lottery_level"
                label="可抽奖人群"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                :width="110"
            >
                <template slot-scope="scope">
                    <p v-if="scope.row.lottery_level == -1">所有用户</p>
                    <p v-else-if="scope.row.lottery_level == 0">至少L0</p>
                    <p v-else-if="scope.row.lottery_level == 1">至少L1</p>
                    <p v-else-if="scope.row.lottery_level == 2">至少L2</p>
                    <p v-else-if="scope.row.lottery_level == 3">至少L3</p>
                    <p v-else-if="scope.row.lottery_level == 4">至少L4</p>
                    <p v-else-if="scope.row.lottery_level == 5">至少L5</p>
                    <p v-else-if="scope.row.lottery_level == 6">至少L6</p>
                    <p v-else>--</p>
                </template>
            </el-table-column>
            <el-table-column
                prop="lottery_num"
                label="中奖名额"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                sortable
                :width="100"
            />
            <el-table-column
                prop="lottery_time"
                label="开奖时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                sortable
                :width="140"
            >
                <template slot-scope="scope">
                    {{ scope.row.lottery_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                prop="join_num"
                label="参与人数"
                show-overflow-tooltip
                align="center"
                sortable
                :width="100"
            />
            <el-table-column
                prop="win_num"
                label="中奖个数"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                sortable
                :width="100"
            >
                <template slot-scope="scope">
                    <p
                        @click="fnSeeWinNumber(scope.row)"
                        class="cursor-font"
                    >
                        {{ scope.row.win_num }}
                    </p>
                </template>
            </el-table-column>
            <el-table-column
                prop="exchange_num"
                label="兑奖个数"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                sortable
                :width="100"
            >
                <template slot-scope="scope">
                    <p
                        @click="fnSeeCashNumber(scope.row)"
                        class="cursor-font"
                    >
                        {{ scope.row.exchange_num }}
                    </p>
                </template>
            </el-table-column>
            <el-table-column
                prop="lottery_sort"
                label="排序"
                :width="120"
                align="center"
            >
                <template slot-scope="scope">
                    <div class="sort-wrap">
                        {{ scope.row.lottery_sort }}
                        <span class="sort-spliter" />
                        <el-button
                            type="text"
                            class="btn-sort"
                            @click="fnEditSort(scope.row)"
                        >
                            <i class="el-icon-edit" />
                        </el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="lottery_show"
                label="上架状态"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            >
                <template slot-scope="scope">
                    <p v-if="scope.row.lottery_show == 1">已上架</p>
                    <p v-if="scope.row.lottery_show == 0">已下架</p>
                </template>
            </el-table-column>
            <el-table-column
                prop="lottery_scope"
                label="活动形式"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            >
                <template slot-scope="scope">
                    <p v-if="scope.row.lottery_scope == 'public'">公开参与</p>
                    <p v-else-if="scope.row.lottery_scope == 'private'">隐藏参与</p>
                    <p
                        v-if="scope.row.lottery_scope == 'private'"
                        class="cursor-font"
                        @click="fnCheckcache(scope.row)"
                    >
                        查看口令
                    </p>
                </template>
            </el-table-column>
            <el-table-column
                prop="lottery_status"
                label="抽奖状态"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            >
                <template slot-scope="scope">
                    <p v-if="scope.row.lottery_status == 1">已开奖</p>
                    <p v-if="scope.row.lottery_status == 0">待开奖</p>
                </template>
            </el-table-column>
            <el-table-column
                prop="create_time"
                label="创建时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
                sortable
                :width="140"
            >
                <template slot-scope="scope">
                    {{ scope.row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
                fixed="right"
                :width="80"
            >
                <template slot-scope="scope">
                    <div class="fixed_right">
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="fnEdit(scope.row)"
                        >
                            编辑
                        </el-button>
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="fnSetShow(scope.row)"
                            v-if="scope.row.lottery_show == 0"
                        >
                            上架
                        </el-button>
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="fnSetShow(scope.row)"
                            v-if="scope.row.lottery_show == 1"
                        >
                            下架
                        </el-button>
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="fnSetActive(scope.row)"
                            v-if="scope.row.lottery_scope == 'private'"
                        >
                            显示
                        </el-button>
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="fnSetActive(scope.row)"
                            v-if="scope.row.lottery_scope == 'public'"
                        >
                            隐藏
                        </el-button>
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="fnDelete(scope.row)"
                        >
                            删除
                        </el-button>
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="fnGetBlackList(scope.row)"
                        >
                            黑名单
                        </el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-checkbox
                v-model="checkedAll"
                :indeterminate="checkIndeterminate"
                @change="fnChangeChecked()"
            >全选</el-checkbox>
            <el-button
                type="text"
                @click="fnBatchRemove()"
                :disabled="multipleSelection.length == 0 ? true : false"
            >批量删除</el-button>
            <el-button
                type="text"
                @click="fnBatchShelf()"
                :disabled="multipleSelection.length == 0 ? true : false"
            >批量下架</el-button>
            <el-button
                type="text"
                @click="fnBatchonShelf()"
                :disabled="multipleSelection.length == 0 ? true : false"
            >批量上架</el-button>
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>

        <!-- 中奖个数 -->
        <el-dialog
            :visible.sync="dialogWinNumber"
            :close-on-click-modal="false"
            width="620px"
        >
            <el-table
                :data="tableWinData"
                height="100%"
                style="width: 100%;max-height:450px"
                border
            >
                <el-table-column
                    type="index"
                    width="80"
                    label="序号"
                    align="center"
                />
                <el-table-column
                    prop="student_no"
                    label="中奖用户ID"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    prop="agent_level"
                    label="用户等级"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                >
                    <template slot-scope="scope">
                        <p v-if="scope.row.agent_level == -1">所有用户</p>
                        <p v-else>E{{ scope.row.agent_level }}}</p>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="join_time"
                    label="参与抽奖时间"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                >
                    <template slot-scope="scope">
                        {{ scope.row.join_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>

        <!-- 兑奖个数 -->
        <el-dialog
            :visible.sync="dialogCash"
            :close-on-click-modal="false"
            width="620px"
        >
            <el-table
                :data="tableWinData"
                height="100%"
                style="width: 100%;max-height:450px"
                border
            >
                <el-table-column
                    type="index"
                    width="80"
                    label="序号"
                    align="center"
                />
                <el-table-column
                    prop="student_no"
                    label="兑奖用户ID"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    prop="agent_level"
                    label="用户等级"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                >
                    <template slot-scope="scope">
                        <p v-if="scope.row.agent_level == -1">所有用户</p>
                        <p v-else>E{{ scope.row.agent_level }}}</p>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="exchange_time"
                    label="兑奖时间"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                >
                    <template slot-scope="scope">
                        {{ scope.row.exchange_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>

        <!-- 补贴抽奖流水 -->
        <el-dialog
            :visible.sync="dialogSubsidy"
            :close-on-click-modal="false"
            width="1020px"
        >
            <p class="zd-subsidy">
                <span>总抽奖补贴金额: {{ Number(money.all).toFixed(2) * 1 }}</span>
                <span>微信支付总补贴: {{ money.wxpay }}</span>
                <span>支付宝支付总补贴: {{ money.alipay }}</span>
                <span>微信服务商总补贴: {{ money.wxpay_service }}</span>
                <span>支付宝服务商总补贴: {{ money.alipay_service }}</span>
            </p>
            <el-table
                :data="tableSubsidyData"
                height="100%"
                style="width: 100%;max-height:450px"
                border
            >
                <el-table-column
                    prop="day_time"
                    label="时间"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                >
                    <template slot-scope="scope">
                        {{ scope.row.day_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="wxpay"
                    label="微信支付补贴"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    prop="alipay"
                    label="支付宝支付补贴"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    prop="wxpay_service"
                    label="微信服务商补贴"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    prop="alipay_service"
                    label="支付宝服务商补贴"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    prop="all"
                    label="当日总额补贴"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                >
                    <template slot-scope="scope">
                        {{ Number(scope.row.all).toFixed(2) * 1 }}
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>

        <!-- 黑名单 -->
        <el-dialog
            :visible.sync="dialogBlack"
            :close-on-click-modal="false"
            title="黑名单列表"
            width="620px"
            class="blackList"
        >
            <el-table
                :data="blackList"
                height="100%"
                style="width: 100%;max-height:500px"
                border
            >
                <el-table-column
                    prop="true_name"
                    label="姓名"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    prop="student_no"
                    label="编号"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    label="操作"
                    align="center"
                >
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="fnDeleteLotter(scope.row)"
                        >
                            移除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="black-foot">
                <el-button
                    size="small"
                    type="default"
                    @click="dialogBlack = false"
                >
                    返回列表
                </el-button>
                <el-button
                    size="small"
                    type="primary"
                    :style="{marginLeft: '42px'}"
                    @click="dialogVisibleBind = true"
                >
                    添加黑名单用户
                </el-button>
            </div>
        </el-dialog>

        <!-- 选择用户 -->
        <el-dialog
            title="选择用户"
            :visible.sync="dialogVisibleBind"
            width="580px"
            :close-on-click-modal="false"
            center
            class="dialogVisibleBind"
        >
            <el-form
                :model="ruleFormBind"
                label-width="100px"
                class="demo-ruleForm"
                @submit.native.prevent
            >
                <el-form-item
                    label="用户:"
                >
                    <el-input
                        v-model="ruleFormBind.phone"
                        size="small"
                        @keyup.native.enter="fnBindSearch()"
                        placeholder="手机号或用户ID"
                        :style="{'width': '350px'}"
                    />
                    <el-button
                        type="primary"
                        size="small"
                        @click="fnBindSearch()"
                    >
                        搜索
                    </el-button>
                </el-form-item>
                <el-table
                    :data="tableDataBind"
                    height="100%"
                    style="width: 100%;max-height:500px"
                    border
                    v-if="tableDataBind.length > 0"
                >
                    <el-table-column
                        label="用户姓名"
                        prop="true_name"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        label="电话号码"
                        prop="phone"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        label="学校名称"
                        prop="school_name"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        label="操作"
                        prop="school_name"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <span
                                @click="fnSelectKf(scope.row, true)"
                                class="el-delData"
                                v-if="!scope.row.flag"
                            >选择</span>
                            <span
                                @click="fnSelectKf(scope.row, false)"
                                class="el-delData"
                                v-if="scope.row.flag"
                            >已选</span>
                        </template>
                    </el-table-column>
                </el-table>
            </el-form>
            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    @click="dialogVisibleBind = false"
                    size="small"
                >取消添加</el-button>
                <el-button
                    type="primary"
                    size="small"
                    @click="fnConirmBind()">确定添加</el-button>
            </span>
        </el-dialog>

        <!-- 批量添加商品 -->
        <search-dialog ref='searchDialog'/>

        <!-- 中奖查询 -->
        <luck-check ref="luckCheck" />

        <!-- 查看口令 -->
        <el-dialog
            title="查看口令"
            :visible.sync="dialogVisibCache"
            width="580px"
            :close-on-click-modal="false"
            class="cache"
        >
            <div class="cache-wrap">
                <div class="cache-list">
                    <p class="cache-list-text">链接: {{ cache.url }}</p>
                    <el-button
                        size="small"
                        type="primary"
                        :style="{width: '120px', height: '32px'}"
                        @click="fnCopy(cache.url)"
                    >
                        复制链接
                    </el-button>
                </div>
                <div class="cache-list">
                    <p class="cache-list-text">口令: {{ cache.code }}</p>
                    <el-button
                        size="small"
                        type="primary"
                        :style="{width: '120px', height: '32px'}"
                        @click="fnCopy(cache.code, cache.name)"
                    >
                        复制口令
                    </el-button>
                </div>
                <p class="cache-tip">注:口令和链接打开的都是同一个页面,链接方便APP端使用,口令方便微信端使用</p>
            </div>
        </el-dialog>

        <!-- 图片预览 -->
        <img-preview ref="preview" />
    </div>
</template>

<script>
import imgPreview from '@/components/common/img-preview';
import searchDialog from '@/components/student/luck/add-shop.vue';
import luckCheck from '@/components/student/luck/luck-check';
import { back } from '@/mixin/back';
export default {
    mixins: [back],
    components: {
        imgPreview,
        searchDialog,
        luckCheck
    },
    data () {
        return {
            cache: {
                url: '',
                code: '',
                name: ''
            },
            dialogVisibCache: false,
            lottery_no: '',
            student_no: [],
            tableDataBind: [],
            ruleFormBind: {
                phone: ''
            },
            dialogVisibleBind: false,
            blackList: [],
            dialogBlack: false,//黑名单
            checkIndeterminate: false,
            multipleSelection: [],
            checkedAll: false,
            money: {//补贴抽奖流水金额数据
                all: 0,
                wxpay: 0,
                alipay: 0,
                wxpay_service: 0,
                alipay_service: 0
            },
            dialogShop: false,//批量添加商品弹窗开关
            tableSubsidyData: [],//补贴抽奖流水弹窗数据
            dialogSubsidy: false,//补贴抽奖流水弹窗开关
            tableWinData: [],//兑奖/抽奖数据存储源，每次打开弹窗重新覆值即可
            dialogCash: false,//兑奖个数弹窗开关
            dialogWinNumber: false,//抽奖个数弹窗开关
            head: {//筛选字段
                luck_status: '',
                shop_name: '',
                shop_leavel: '',
                luck_start_time: '',
                luck_end_time: '',
                show_status: '',
                lottery_scope: ''
            },
            leavelData: [{
                value: -1,
                label: '所有用户'
            },{
                value: 0,
                label: 'L0'
            },{
                value: 1,
                label: 'L1'
            },{
                value: 2,
                label: 'L2'
            },{
                value: 3,
                label: 'L3'
            },{
                value: 4,
                label: 'L4'
            },{
                value: 5,
                label: 'L5'
            },{
                value: 6,
                label: 'L6'
            }],
            showList: [{
                value: '',
                label: '全部'
            },{
                value: 1,
                label: '已上架'
            },{
                value: 0,
                label: '已下架'
            }],
            activeList: [{
                value: '',
                label: '全部'
            },{
                value: 'public',
                label: '公开参与'
            },{
                value: 'private',
                label: '隐藏参与'
            }],
            filterData: {
                sort_field: 'asc',
                sort_type: 'desc'
            },
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            tableData: [],
            authResult: {}
        };
    },
    filters: {
    },
    computed: {},
    watch: {
        dialogVisibleBind (val) {
            if(!val) {
                this.student_no = [];
                this.tableDataBind = [];
            }
        }
    },
    created () {

    },
    mounted () {
        this.$store.commit('SET_HEADER', [{ title: "APP后台"},{title: '商城'},{title: '抽奖商品管理'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();

        this.$nextTick(()=>{
            let query = this.$route.query;

            if(query.lottery_dialog) {
                this.$refs.luckCheck.showDialog();
            }
        });
    },
    methods: {
        /**
         * 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/shop_lottery%5Cget_list', {
                page_id: page || this.page.now_page,
                keyword: this.head.shop_name,
                lottery_status: this.head.luck_status,
                lottery_show: this.head.show_status,
                lottery_level: this.head.shop_leavel,
                start_time: this.head.luck_start_time === null || this.head.luck_start_time == '' ? '' : new Date(this.head.luck_start_time).getTime() / 1000,
                end_time: this.head.luck_end_time === null || this.head.luck_end_time == '' ? '' : new Date(this.head.luck_end_time).getTime() / 1000,
                sort_field: this.filterData.sort_field,
                sort_type: this.filterData.sort_type,
                lottery_scope: this.head.lottery_scope
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                }
            });
        },

        /**
         * @description 查看口令
         */
        fnCheckcache (row) {
            this.$post('/student/shop_lottery%5Cget_share', {
                lottery_no: row.lottery_no
            }, resp => {
                if (resp.code == 1) {
                    let url = {
                        dev: 'http://student-dev.wxhand.com',
                        production: 'http://student.zsdx.cn'
                    };

                    if(location.host == 'localhost:8080' || location.host == 'nadmin.wxhand.com') {
                        this.cache = {
                            url: url.dev + '/pages/mall/lottery/lottery-goods-detail?lottery_no=' + resp.data.lottery_no,
                            code: resp.data.zsdx_pwd,
                            name: row.goods_title
                        };
                    } else {
                        this.cache = {
                            url: url.production + '/pages/mall/lottery/lottery-goods-detail?lottery_no=' + resp.data.lottery_no,
                            code: resp.data.zsdx_pwd,
                            name: row.goods_title
                        };
                    }

                    this.dialogVisibCache = !this.dialogVisibCache;
                }
            });
        },

        /**
         * @description 复制内容
         */
        fnCopy (text, name) {
            if(name) {
                let str = '复制信息##' + text + '##打开👉掌上大学👈参与抽奖【' + name + '】';
                let oInput = document.createElement("input");

                oInput.value = str;
                document.body.appendChild(oInput);
                oInput.select();
                document.execCommand("Copy");
                oInput.style.display = "none";
                this.$message.success('复制成功');
            } else {
                let str = text;
                let oInput = document.createElement("input");

                oInput.value = str;
                document.body.appendChild(oInput);
                oInput.select();
                document.execCommand("Copy");
                oInput.style.display = "none";
                this.$message.success('复制成功');
            }
        },

        /**
         * @description 删除黑名单用户
         */
        fnDeleteLotter (row) {
            let no = this.blackList.reduce((cur,next) => {
                cur.push(next.student_no);
                return cur;
            },[]);

            let list = no.filter(item => row.student_no !== item);

            this.$confirm('是否要移除该用户', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$post('/student/shop_lottery%5Cset_win_config',{
                    lottery_no: this.lottery_no,
                    cannot_win_student_nos: list.join()
                },resp=>{
                    if (resp.code == 1) {
                        setTimeout(()=>{
                            this.$post('/student/shop_lottery%5Cget_win_config',{
                                lottery_no: this.lottery_no
                            },resp=>{
                                if (resp.code == 1) {
                                    this.blackList = resp.data.cannot_win_student_list;
                                } else if (resp.code == 0) {
                                    this.$message({
                                        type: 'warning',
                                        message: resp.msg
                                    });
                                }
                            });
                        },100);
                    } else if (resp.code == 0) {
                        this.$message({
                            type: 'waring',
                            message: resp.msg,
                            center: true
                        });
                    }
                });
            });
        },

        /**
         * 打开黑名单弹窗
         */
        fnGetBlackList (row) {
            if(!this.authResult.auth_get_black) {
                this.$message({
                    type: 'waring',
                    message: '请联系管理员添加权限',
                    center: true
                });
                return;
            }

            this.lottery_no = row.lottery_no;
            this.$post('/student/shop_lottery%5Cget_win_config',{
                lottery_no: row.lottery_no
            },resp=>{
                if (resp.code == 1) {
                    this.blackList = resp.data.cannot_win_student_list;
                    this.dialogBlack = !this.dialogBlack;
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * 选择用户
         */
        fnSelectKf (row, type) {
            if(type) {
                this.student_no.push(row.student_no);
                this.$set(row,'flag', type);
                return;
            }
            if(!type) {
                this.student_no = this.student_no.filter(item => item !== row.student_no);

                this.$set(row,'flag', type);
                return;
            }
        },

        /**
         * 搜索
         */
        fnBindSearch () {
            this.$post('/student/student_user%5Cget_list_suggest',{
                keyword: this.ruleFormBind.phone
            },resp=>{
                if (resp.code == 1) {
                    if (resp.data.list.length == 0) {
                        this.$message({
                            type: 'waring',
                            message: '该用户不存在'
                        });
                        this.ruleFormBind.phone = '';
                        return;
                    }
                    this.tableDataBind = resp.data.list;
                    this.ruleFormBind.phone = '';

                    this.tableDataBind.filter(item => {
                        if(this.student_no.includes(item.student_no)) {
                            item.flag = true;
                        }
                    });
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'waring',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * 添加黑名单
         */
        fnConirmBind () {
            if(!this.authResult.auth_black) {
                this.$message({
                    type: 'waring',
                    message: '请联系管理员添加权限',
                    center: true
                });
                return;
            }

            if(this.student_no.length == 0) {
                this.$message({
                    type: 'waring',
                    message: '请先选择用户'
                });
                return;
            }

            let list = this.blackList.reduce((cur,next) => {
                cur.push(next.student_no);
                return cur;
            },[]);

            let data = list.concat(this.student_no);

            this.$post('/student/shop_lottery%5Cset_win_config',{
                lottery_no: this.lottery_no,
                cannot_win_student_nos: data.join()
            },resp=>{
                if (resp.code == 1) {
                    this.blackList = [];
                    this.dialogVisibleBind = !this.dialogVisibleBind;
                    setTimeout(()=>{
                        this.$post('/student/shop_lottery%5Cget_win_config',{
                            lottery_no: this.lottery_no
                        },resp=>{
                            if (resp.code == 1) {
                                this.blackList = resp.data.cannot_win_student_list;
                            } else if (resp.code == 0) {
                                this.$message({
                                    type: 'warning',
                                    message: resp.msg
                                });
                            }
                        });
                    },100);
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'waring',
                        message: resp.msg,
                        center: true
                    });
                }
            });
        },

        /**
         * 查看自营商品
         */
        fnJumpShop (row) {
            let routeData = this.$router.resolve({
                name: 'GoodsList',
                query: {
                    goods_title: row.goods_title,
                    goods_type: 'self'
                }
            });

            window.open(routeData.href, '_blank');
        },

        /**
         * 查看中奖个数数据
         */
        fnSeeWinNumber (row) {
            this.$post('/student/shop_lottery%5Cget_lottery_student_list',{
                lottery_no: row.lottery_no,
                type: 1
            },resp=>{
                if (resp.code == 1) {
                    this.tableWinData = resp.data.list;
                    this.dialogWinNumber = !this.dialogWinNumber;
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * 查看兑奖个数数据
         */
        fnSeeCashNumber (row) {
            this.$post('/student/shop_lottery%5Cget_lottery_student_list',{
                lottery_no: row.lottery_no,
                type: 2
            },resp=>{
                if (resp.code == 1) {
                    this.tableWinData = resp.data.list;
                    this.dialogCash = !this.dialogCash;
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * 查看补贴抽奖流水
         */
        fnSubsidyDialog () {
            if(!this.authResult.auth_subsidy) {
                this.$message({
                    type: 'warning',
                    message: '此权限，仅限超级管理员'
                });
                return;
            }

            this.$post('/student/shop_lottery%5Cget_statistic_subsidy_money',{},resp=>{
                if (resp.code == 1) {
                    this.money = {
                        ...resp.data.all
                    };
                    this.tableSubsidyData = resp.data.day;
                    this.dialogSubsidy = !this.dialogSubsidy;
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * 打开中奖查询弹窗
         */
        fnLuckCheck () {
            this.$refs.luckCheck.showDialog();
        },

        /**
         * 上架/下架
         */
        fnSetShow (row) {
            this.$post('/student/shop_lottery%5Cset_show',{
                lottery_no: row.lottery_no,
                lottery_show: row.lottery_show == 1 ? 0 : 1
            },resp=>{
                if (resp.code == 1) {
                    this.getTableData();
                    this.$message({
                        type: 'success',
                        message: '操作成功'
                    });
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * 显示/隐藏
         */
        fnSetActive (row) {
            this.$post('/student/shop_lottery%5Cset_scope',{
                lottery_no: row.lottery_no,
                lottery_scope: row.lottery_scope == 'public' ? 'private' : 'public'
            },resp=>{
                if (resp.code == 1) {
                    this.getTableData();
                    this.$message({
                        type: 'success',
                        message: '操作成功'
                    });
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * 删除商品
         */
        fnDelete (row) {
            this.$confirm('此操作将删除该商品, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$post('/student/shop_lottery%5Cdelete',{
                    lottery_no: row.lottery_no
                },resp=>{
                    if (resp.code == 1) {
                        this.getTableData();
                        this.$message({
                            type: 'success',
                            message: '删除成功'
                        });
                    } else if (resp.code == 0) {
                        this.$message({
                            type: 'warning',
                            message: resp.msg
                        });
                    }
                });
            });
        },

        /**
         * 批量删除
         */
        fnBatchRemove () {
            this.$confirm('是否批量删除选中商品', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.multipleSelection.forEach(option => {
                    this.$post('/student/shop_lottery%5Cdelete',{
                        lottery_no: option.lottery_no
                    },resp=>{
                        if (resp.code == 1) {
                            //
                        }
                    });
                });

                setTimeout(()=>{
                    this.getTableData();
                    this.$message({
                        type: 'success',
                        message: '删除成功'
                    });
                },200);
            });
        },

        /**
         * 批量下架
         */
        fnBatchShelf () {
            this.$confirm('是否批量下架选中商品', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.multipleSelection.forEach(option => {
                    this.$post('/student/shop_lottery%5Cset_show',{
                        lottery_no: option.lottery_no,
                        lottery_show: 0
                    },resp=>{
                        if (resp.code == 1) {
                            //
                        }
                    });
                });

                setTimeout(()=>{
                    this.getTableData();
                    this.$message({
                        type: 'success',
                        message: '下架成功'
                    });
                },200);
            });
        },

        /**
         * 批量上架
         */
        fnBatchonShelf () {
            this.$confirm('是否批量上架选中商品', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.multipleSelection.forEach(option => {
                    this.$post('/student/shop_lottery%5Cset_show',{
                        lottery_no: option.lottery_no,
                        lottery_show: 1
                    },resp=>{
                        if (resp.code == 1) {
                            //
                        }
                    });
                });

                setTimeout(()=>{
                    this.getTableData();
                    this.$message({
                        type: 'success',
                        message: '上架成功'
                    });
                },200);
            });
        },

        /**
         * 编辑商品
         */
        fnEdit (row) {
            this.$router.push({
                name: 'zdLuckCreate',
                query: {
                    lottery_no: row.lottery_no,
                    type: 'edit'
                }
            });
        },

        /**
         * 排序
         */
        fnEditSort (row) {
            this.$prompt('请输入排序号', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /^([1-9]\d?|[1-9]\d+)$/,
                inputErrorMessage: '排序号格式不正确,请重新输入'
            }).then(({ value }) => {
                this.$post('/student/shop_lottery%5Cset_sort',{
                    lottery_no: row.lottery_no,
                    lottery_sort: value
                },resp=>{
                    if (resp.code == 1) {
                        this.getTableData();
                        this.$message({
                            type: 'success',
                            message: '操作成功'
                        });
                    } else if (resp.code == 0) {
                        this.$message({
                            type: 'warning',
                            message: resp.msg
                        });
                    }
                });
            });
        },

        /**
         * 数据排序
         */
        handleSortChanged(data) {
            console.log(data);
            let sortTypeMap = {
                ascending: 'asc',
                descending: 'desc'
            };

            let sortFieldMap = {
                lottery_price: 'lottery_price',
                lottery_time: 'lottery_time',
                join_num: 'join_num',
                win_num: 'win_num',
                exchange_num: 'exchange_num',
                create_time: 'create_time',
                lottery_num: '"lottery_num"'
            };

            if (data.order) {
                this.filterData.sort_field = sortFieldMap[data.prop];
                this.filterData.sort_type = sortTypeMap[data.order];
            } else {
                this.filterData.sort_field = '';
                this.filterData.sort_type = '';
            }

            this.getTableData();
        },

        /**
         * 查看图片
         * @param   {String}    images      //单图预览
         * @param   {Array}     images      //多图预览
         */
        fnShowPreview(images) {
            if(images && Object.prototype.toString.call(images) == '[object String]') {
                this.$refs.preview.show([
                    images
                ]);
            } else if (images && Object.prototype.toString.call(images) == '[object Array]') {
                this.$refs.preview.show(images);
            } else {
                this.$message({
                    type: 'warning',
                    message: '图片类型错误'
                });
            }
        },

        /**
         * 全选逻辑操作
         */
        fnSelect(selection) {
            if(selection.length == this.tableData.length) {
                this.checkedAll = true;
            }else{
                this.checkedAll = false;
            }
            if(selection.length > 0 && selection.length < this.tableData.length) {
                this.checkIndeterminate = true;
            }else{
                this.checkIndeterminate = false;
            }
        },
        fnSelectAllTop(selection) {
            if(selection.length > 0) {
                this.checkedAll = true;
            }else{
                this.checkedAll = false;
            }
            if(selection.length > 0 && selection.length < this.tableData.length) {
                this.checkIndeterminate = true;
            }else{
                this.checkIndeterminate = false;
            }
        },
        fnChangeChecked() {
            if(this.checkedAll){
                this.toggleSelection(1);
            }else{
                this.toggleSelection();
            }
        },
        toggleSelection(rows) {
            if (rows) {
                this.$refs.zdLuckDraw.toggleAllSelection();
            } else {
                this.$refs.zdLuckDraw.clearSelection();
            }
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },

        /**
         * 默认时间加载
         */
        fnGetPickerOptions () {

            return {
                shortcuts : [{
                    text: '昨天',
                    onClick(picker) {
                        const date = new Date();

                        date.setTime(date.getTime() - 3600 * 1000 * 24);
                        picker.$emit('pick', date);
                    }
                },{
                    text: '今天',
                    onClick(picker) {
                        picker.$emit('pick', new Date());
                    }
                },{
                    text: '明天',
                    onClick(picker) {
                        const date = new Date();

                        date.setTime(date.getTime() + 3600 * 1000 * 24);
                        picker.$emit('pick', date);
                    }
                },{
                    text: '后天',
                    onClick(picker) {
                        const date = new Date();

                        date.setTime(date.getTime() + 3600 * 1000 * 24 * 2);
                        picker.$emit('pick', date);
                    }
                }]
            };
        },

        /**
         * 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 10px 15px 5px 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            .header-left, .header-right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .header-new-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                margin-bottom: 10px;
                white-space: nowrap;
                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            padding-bottom: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        cursor: pointer;
        justify-content: center;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
    .zd-subsidy {
        font-size: 14px;
        margin-bottom: 10px;
        font-weight: 500;
        line-height: 20px;
        font-weight: 500;
        display: flex;
        color: #20a0ff;
        cursor: pointer;
        span:nth-child(n+2) {
            margin-left: 30px;
        }
    }
    .black-foot {
        width: 100%;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: 32px;
    }
    .el-delData {
        color: #20a0ff;
        cursor: pointer;
    }
    .cache-wrap {
        display: flex;
        flex-direction: column;
        .cache-list {
            display: flex;
            height: 32px;
            align-items: center;
            margin-bottom: 15px;
            justify-content: space-between;
            .cache-list-text {
                color: #333;
                width: 380px;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
        }
        .cache-tip {
            color: #999;
            margin-top: 20px;
        }
    }
</style>
<style lang="less">
    .zdLuckDraw{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
        // .el-table__body-wrapper {
        //     &::-webkit-scrollbar {
        //         width: 4px;
        //     }
        // }
        .fixed_right .el-button {
            padding: 0;
            margin-left: 0;
        }
        .blackList .el-table__body-wrapper {
            height: auto !important;
            max-height: 300px !important;
        }
        .dialogVisibleBind .el-table__body-wrapper {
            height: auto !important;
            max-height: 300px !important;
        }
        .cache .el-dialog__header {
            border-bottom: 1px #eeeeee solid;
        }
    }
</style>
